<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>JavaScript启示录阅读笔录 | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="JavaScript,读书笔记,">
  

  <meta name="description" content="第一章 JavaScript对象1.1 创建对象 //创建copy对象var copy = new Object();//为对象的各种属性赋值copy.living = true;copy.age = 33;copy.gender = &apos;male&apos;;// logs Object &amp;#123;living = true, age = 33, gender = &apos;male&apos;&amp;#125;console.">
<meta name="keywords" content="JavaScript,读书笔记">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript启示录阅读笔录">
<meta property="og:url" content="http://blog.poetries.top/2017/10/24/js-read-note/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="第一章 JavaScript对象1.1 创建对象 //创建copy对象var copy = new Object();//为对象的各种属性赋值copy.living = true;copy.age = 33;copy.gender = &apos;male&apos;;// logs Object &amp;#123;living = true, age = 33, gender = &apos;male&apos;&amp;#125;console.">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-08-15T04:25:31.926Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JavaScript启示录阅读笔录">
<meta name="twitter:description" content="第一章 JavaScript对象1.1 创建对象 //创建copy对象var copy = new Object();//为对象的各种属性赋值copy.living = true;copy.age = 33;copy.gender = &apos;male&apos;;// logs Object &amp;#123;living = true, age = 33, gender = &apos;male&apos;&amp;#125;console.">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#第一章-JavaScript对象"><span class="toc-text">第一章 JavaScript对象</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-创建对象"><span class="toc-text">1.1 创建对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-JavaScript构造函数构建并返回对象实例"><span class="toc-text">1.2 JavaScript构造函数构建并返回对象实例</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-3-JavaScript原生内置对象构造函数"><span class="toc-text">1.3 JavaScript原生内置对象构造函数</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#第二章-对象与属性"><span class="toc-text">第二章 对象与属性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-封装复杂对象"><span class="toc-text">2.1 封装复杂对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-用点表示法或中括号表示法获取-设置-更新对象属性"><span class="toc-text">2.2 用点表示法或中括号表示法获取/设置/更新对象属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-删除对象属性"><span class="toc-text">2.3 删除对象属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-使用hasOwnProperty验证对象属性是否来自原型链"><span class="toc-text">2.4 使用hasOwnProperty验证对象属性是否来自原型链</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-使用in操作符来检查一个对象是否包含给定属性"><span class="toc-text">2.5 使用in操作符来检查一个对象是否包含给定属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-6-使用for-in循环枚举对象属性"><span class="toc-text">2.6 使用for in循环枚举对象属性</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#第三章-Object"><span class="toc-text">第三章 Object</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-Object对象概要"><span class="toc-text">3.1 Object对象概要</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-Object对象实例属性和方法"><span class="toc-text">3.2 Object对象实例属性和方法</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#第四章-Function"><span class="toc-text">第四章 Function</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-Function对象属性和方法"><span class="toc-text">4.1 Function对象属性和方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-2-function对象实例属性和方法"><span class="toc-text">4.2 function对象实例属性和方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-3-this和arguments适用于所有函数"><span class="toc-text">4.3 this和arguments适用于所有函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-4-函数实例的length属性和arguments-length"><span class="toc-text">4.4 函数实例的length属性和arguments.length</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-5-定义函数语句、表达式、构造函数"><span class="toc-text">4.5 定义函数语句、表达式、构造函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-6-调用函数（函数、方法、构造函数、call、apply）"><span class="toc-text">4.6 调用函数（函数、方法、构造函数、call、apply）</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#第六章-this关键字"><span class="toc-text">第六章 this关键字</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#6-1-this概要及this如何引用"><span class="toc-text">6.1 this概要及this如何引用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-2-如何确定this值"><span class="toc-text">6.2 如何确定this值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-3-在嵌套函数中用this关键字引用head对象"><span class="toc-text">6.3 在嵌套函数中用this关键字引用head对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-4-充分利用作用域链研究嵌套函数问题"><span class="toc-text">6.4 充分利用作用域链研究嵌套函数问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-5-使用call-、apply-控制this值"><span class="toc-text">6.5 使用call()、apply()控制this值</span></a></li></ol></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-js-read-note" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">JavaScript启示录阅读笔录</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2017.10.24</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 1.8k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 8分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <h2 id="第一章-JavaScript对象"><a href="#第一章-JavaScript对象" class="headerlink" title="第一章 JavaScript对象"></a>第一章 JavaScript对象</h2><h3 id="1-1-创建对象"><a href="#1-1-创建对象" class="headerlink" title="1.1 创建对象"></a>1.1 创建对象</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//创建copy对象</span></span><br><span class="line"><span class="keyword">var</span> copy = <span class="keyword">new</span> <span class="built_in">Object</span>();</span><br><span class="line"></span><br><span class="line"><span class="comment">//为对象的各种属性赋值</span></span><br><span class="line">copy.living = <span class="literal">true</span>;</span><br><span class="line">copy.age = <span class="number">33</span>;</span><br><span class="line">copy.gender = <span class="string">'male'</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// logs Object &#123;living = true, age = 33, gender = 'male'&#125;</span></span><br><span class="line"><span class="built_in">console</span>.log(cody);</span><br></pre></td></tr></table></figure>
<ul>
<li>最重要的是要记住：对象只是属性的容器，每个属性都有一个名称和一个值</li>
</ul>
<h3 id="1-2-JavaScript构造函数构建并返回对象实例"><a href="#1-2-JavaScript构造函数构建并返回对象实例" class="headerlink" title="1.2 JavaScript构造函数构建并返回对象实例"></a>1.2 JavaScript构造函数构建并返回对象实例</h3><hr>
<ul>
<li>构造函数的作用是创建多个共享特定特性和行为的对象。</li>
<li>构造函数主要是用于生成对象的模具，这些对象具有默认属性和属性方法</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//Pserson是一个构造函数 使用new关键字进行实例化</span></span><br><span class="line">  <span class="keyword">var</span> Person = <span class="function"><span class="keyword">function</span>(<span class="params">living,age,gender</span>)</span>&#123;</span><br><span class="line">        <span class="comment">//this表示即将创建的新对象</span></span><br><span class="line">        </span><br><span class="line">        <span class="keyword">this</span>.living = living;</span><br><span class="line">        <span class="keyword">this</span>.age = age;</span><br><span class="line">        <span class="keyword">this</span>.gender = gender;</span><br><span class="line">        <span class="keyword">this</span>.getGender = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">this</span>.gender;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">    <span class="comment">//实例化Person对象 </span></span><br><span class="line">    <span class="keyword">var</span> copy = <span class="keyword">new</span> Person(<span class="literal">true</span>,<span class="number">22</span>,<span class="string">'male'</span>);</span><br><span class="line">    </span><br><span class="line">    <span class="built_in">console</span>.log(copy.constructor);<span class="comment">//输入Person函数</span></span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h3 id="1-3-JavaScript原生内置对象构造函数"><a href="#1-3-JavaScript原生内置对象构造函数" class="headerlink" title="1.3 JavaScript原生内置对象构造函数"></a>1.3 JavaScript原生内置对象构造函数</h3><hr>
<ul>
<li><p><code>JavaScript</code>包含九个原生对象构造函数，<code>JavaScript</code>使用这些对象来构建<code>JavaScript</code>语言</p>
</li>
<li><p><code>Number()</code></p>
</li>
<li><code>String()</code></li>
<li><code>Boolean()</code></li>
<li><code>Object()</code></li>
<li><code>Array()</code></li>
<li><code>Function()</code></li>
<li><code>Date()</code></li>
<li><code>RegExp()</code></li>
<li><p><code>Error()</code></p>
</li>
<li><p>使用<code>new</code>关键字实例化每个原生构造函数</p>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> number = <span class="keyword">new</span> <span class="built_in">Number</span>(<span class="number">22</span>);</span><br><span class="line"><span class="keyword">var</span> string = <span class="keyword">new</span> <span class="built_in">String</span>(<span class="string">"male"</span>);</span><br><span class="line"><span class="keyword">var</span> boolean = <span class="keyword">new</span> <span class="built_in">Boolean</span>(<span class="literal">false</span>);</span><br><span class="line"><span class="keyword">var</span> obj = <span class="keyword">new</span> <span class="built_in">Object</span>();</span><br><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="string">"foo"</span>,<span class="string">"dfa"</span>);</span><br><span class="line"><span class="keyword">var</span> func = <span class="keyword">new</span> <span class="built_in">Function</span>(<span class="string">"x"</span>,<span class="string">"y"</span>,<span class="string">"return x*y"</span>);</span><br><span class="line"><span class="keyword">var</span> date = <span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line"><span class="keyword">var</span> reg = <span class="keyword">new</span> <span class="built_in">RegExp</span>(<span class="string">'\bt[a-z]+\b'</span>);</span><br><span class="line"><span class="keyword">var</span> error = <span class="keyword">new</span> <span class="built_in">Error</span>(<span class="string">"Crap"</span>);</span><br></pre></td></tr></table></figure>
<h2 id="第二章-对象与属性"><a href="#第二章-对象与属性" class="headerlink" title="第二章 对象与属性"></a>第二章 对象与属性</h2><hr>
<h3 id="2-1-封装复杂对象"><a href="#2-1-封装复杂对象" class="headerlink" title="2.1 封装复杂对象"></a>2.1 封装复杂对象</h3><hr>
<ul>
<li><code>Object()</code>、<code>Array()</code>、 <code>Function()</code>对象可以包含其他复杂对象</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//使用对象封装，创建对象链</span></span><br><span class="line"><span class="keyword">var</span> obj1 = &#123;</span><br><span class="line">    obj1_1: &#123;</span><br><span class="line">        obj1_1_1: &#123;&#125;</span><br><span class="line">    &#125;,</span><br><span class="line">     obj1_2: &#123;</span><br><span class="line">        obj1_2_1: &#123;&#125;</span><br><span class="line">    &#125;,</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//使用数组封装 创建多维数组链</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> myArr = [ [ [] ] ];</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//使用function封装</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> myFunc = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">    va myfunc = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">var</span> myfunc = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="2-2-用点表示法或中括号表示法获取-设置-更新对象属性"><a href="#2-2-用点表示法或中括号表示法获取-设置-更新对象属性" class="headerlink" title="2.2 用点表示法或中括号表示法获取/设置/更新对象属性"></a>2.2 用点表示法或中括号表示法获取/设置/更新对象属性</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// creating cody Object() object</span></span><br><span class="line"><span class="keyword">var</span> cody = <span class="keyword">new</span> <span class="built_in">Object</span>();</span><br><span class="line"></span><br><span class="line"><span class="comment">// setting properties</span></span><br><span class="line">cody[<span class="string">'living'</span>] = <span class="literal">true</span>;</span><br><span class="line">cody[<span class="string">'age'</span>] = <span class="number">33</span>; </span><br><span class="line">cody[<span class="string">'gender'</span>] = <span class="string">'male'</span>;</span><br><span class="line">cody[<span class="string">'getGender'</span>] = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="keyword">return</span> cody.gender;&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">// getting properties</span></span><br><span class="line"><span class="built_in">console</span>.log(</span><br><span class="line">    cody[<span class="string">'living'</span>], </span><br><span class="line">    cody[<span class="string">'age'</span>], </span><br><span class="line">    cody[<span class="string">'gender'</span>], </span><br><span class="line">    cody[<span class="string">'getGender'</span>]() <span class="comment">// just slap the function invocation on the end!</span></span><br><span class="line">); <span class="comment">// logs 'true 33 male male'</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// updating properties, very similar to setting</span></span><br><span class="line">cody[<span class="string">'living'</span>] = <span class="literal">false</span>;</span><br><span class="line">cody[<span class="string">'age'</span>] = <span class="number">99</span>; </span><br><span class="line">cody[<span class="string">'gender'</span>] = <span class="string">'female'</span>;</span><br><span class="line">cody[<span class="string">'getGender'</span>] = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="keyword">return</span> <span class="string">'Gender = '</span> + cody.gender;&#125;;</span><br></pre></td></tr></table></figure>
<h3 id="2-3-删除对象属性"><a href="#2-3-删除对象属性" class="headerlink" title="2.3 删除对象属性"></a>2.3 删除对象属性</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> foo = &#123;<span class="attr">bar</span>:<span class="string">"bar"</span>&#125;;</span><br><span class="line"><span class="keyword">delete</span> foo.bar;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"bar"</span> <span class="keyword">in</span> foo);</span><br></pre></td></tr></table></figure>
<h3 id="2-4-使用hasOwnProperty验证对象属性是否来自原型链"><a href="#2-4-使用hasOwnProperty验证对象属性是否来自原型链" class="headerlink" title="2.4 使用hasOwnProperty验证对象属性是否来自原型链"></a>2.4 使用hasOwnProperty验证对象属性是否来自原型链</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;<span class="attr">foo</span>:<span class="string">"value"</span>&#125;;</span><br><span class="line"><span class="built_in">console</span>.log(obj.hasOwnProperty(<span class="string">"foo"</span>));<span class="comment">//true</span></span><br></pre></td></tr></table></figure>
<h3 id="2-5-使用in操作符来检查一个对象是否包含给定属性"><a href="#2-5-使用in操作符来检查一个对象是否包含给定属性" class="headerlink" title="2.5 使用in操作符来检查一个对象是否包含给定属性"></a>2.5 使用in操作符来检查一个对象是否包含给定属性</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> myObject = &#123;<span class="attr">foo</span>: <span class="string">'value'</span>&#125;;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'foo'</span> <span class="keyword">in</span> myObject); <span class="comment">// logs true</span></span><br></pre></td></tr></table></figure>
<h3 id="2-6-使用for-in循环枚举对象属性"><a href="#2-6-使用for-in循环枚举对象属性" class="headerlink" title="2.6 使用for in循环枚举对象属性"></a>2.6 使用for in循环枚举对象属性</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> copy = &#123;</span><br><span class="line">    age:<span class="number">23</span>,</span><br><span class="line">    gender:<span class="string">'male'</span></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> key <span class="keyword">in</span> copy)&#123;<span class="comment">//key表示每个属性的名称</span></span><br><span class="line">    <span class="keyword">if</span>(copy.hasOwnproperty(key))&#123; <span class="comment">//避免来自原型链的属性</span></span><br><span class="line">        <span class="built_in">console</span>.log(key);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="第三章-Object"><a href="#第三章-Object" class="headerlink" title="第三章 Object"></a>第三章 Object</h2><h3 id="3-1-Object对象概要"><a href="#3-1-Object对象概要" class="headerlink" title="3.1 Object对象概要"></a>3.1 Object对象概要</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> copy = &#123;&#125;;</span><br><span class="line"><span class="keyword">for</span> (key <span class="keyword">in</span> copy)&#123;</span><br><span class="line">    <span class="keyword">if</span>(copy.hasOwnproperty(key))&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(key);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="3-2-Object对象实例属性和方法"><a href="#3-2-Object对象实例属性和方法" class="headerlink" title="3.2 Object对象实例属性和方法"></a>3.2 Object对象实例属性和方法</h3><hr>
<ul>
<li>实例属性 <ul>
<li><code>constructor</code></li>
</ul>
</li>
<li>实例方法<ul>
<li><code>hasOwnProperty()</code></li>
<li><code>isPrototypeOf()</code></li>
<li><code>propertyIsEnumerable()</code></li>
<li><code>toLocaleString()</code></li>
<li><code>toString()</code></li>
<li><code>valueOf()</code></li>
</ul>
</li>
</ul>
<h2 id="第四章-Function"><a href="#第四章-Function" class="headerlink" title="第四章 Function"></a>第四章 Function</h2><h3 id="4-1-Function对象属性和方法"><a href="#4-1-Function对象属性和方法" class="headerlink" title="4.1 Function对象属性和方法"></a>4.1 Function对象属性和方法</h3><hr>
<ul>
<li>属性 <code>prototype</code></li>
</ul>
<h3 id="4-2-function对象实例属性和方法"><a href="#4-2-function对象实例属性和方法" class="headerlink" title="4.2 function对象实例属性和方法"></a>4.2 function对象实例属性和方法</h3><hr>
<ul>
<li><p>实例属性</p>
<ul>
<li><code>arguments</code></li>
<li><code>constructor</code></li>
<li><code>length</code></li>
</ul>
</li>
<li><p>实例方法</p>
<ul>
<li><code>apply()</code></li>
<li><code>call()</code></li>
<li><code>toString()</code></li>
</ul>
</li>
</ul>
<h3 id="4-3-this和arguments适用于所有函数"><a href="#4-3-this和arguments适用于所有函数" class="headerlink" title="4.3 this和arguments适用于所有函数"></a>4.3 <code>this</code>和<code>arguments</code>适用于所有函数</h3><hr>
<ul>
<li><p>在所有函数的作用域、函数体内，<code>this</code>和<code>arguments</code>值都是可用的</p>
</li>
<li><p><code>arguments</code>对象是一种类数组对象，它包含所有传递给函数的参数</p>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> add = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">arguments</span>[<span class="number">0</span>] + <span class="built_in">arguments</span>[<span class="number">1</span>];</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(add(<span class="number">4</span>,<span class="number">4</span>));<span class="comment">//8</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> myObject1 = &#123;</span><br><span class="line">    name: <span class="string">'myObject1'</span>,</span><br><span class="line">    myMethod: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;<span class="built_in">console</span>.log(<span class="keyword">this</span>.name);&#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">myObject1.myMethod(); <span class="comment">// logs 'myObject1'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> myObject2 = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;<span class="built_in">console</span>.log(<span class="keyword">this</span>);&#125;; </span><br><span class="line"></span><br><span class="line">myObject2(); <span class="comment">// logs Window</span></span><br></pre></td></tr></table></figure>
<h3 id="4-4-函数实例的length属性和arguments-length"><a href="#4-4-函数实例的length属性和arguments-length" class="headerlink" title="4.4 函数实例的length属性和arguments.length"></a>4.4 函数实例的length属性和arguments.length</h3><hr>
<ul>
<li><code>argument</code>对象有一个独特的<code>length</code>属性，它给出的是在调用时发送给函数的参数数量</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> myObject1 = &#123;</span><br><span class="line">    name: <span class="string">'myObject1'</span>,</span><br><span class="line">    myMethod: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;<span class="built_in">console</span>.log(<span class="keyword">this</span>.name);&#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">myObject1.myMethod(); <span class="comment">// logs 'myObject1'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> myObject2 = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;<span class="built_in">console</span>.log(<span class="keyword">this</span>);&#125;; </span><br><span class="line"></span><br><span class="line">myObject2(); <span class="comment">// logs Window</span></span><br></pre></td></tr></table></figure>
<ul>
<li>通过<code>Function()</code>实例的<code>length</code>属性，实际上可以获得函数所需要的参数总数量</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> myFunction = <span class="function"><span class="keyword">function</span>(<span class="params">z, s, d, e, r, m, q</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> myFunction.length;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(myFunction()); <span class="comment">//logs 7</span></span><br></pre></td></tr></table></figure>
<h3 id="4-5-定义函数语句、表达式、构造函数"><a href="#4-5-定义函数语句、表达式、构造函数" class="headerlink" title="4.5 定义函数语句、表达式、构造函数"></a>4.5 定义函数语句、表达式、构造函数</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//函数构造函数</span></span><br><span class="line"><span class="keyword">var</span> addConstructor = <span class="keyword">new</span> <span class="built_in">Function</span>(<span class="string">"x"</span>,<span class="string">"y"</span>,<span class="string">"return x + y"</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//函数语句</span></span><br><span class="line"><span class="function"><span class="keyword">function</span>  <span class="title">addStatement</span>(<span class="params">x,y</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> x + y;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//函数表达式</span></span><br><span class="line"><span class="keyword">var</span> addExp = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> x + y;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="4-6-调用函数（函数、方法、构造函数、call、apply）"><a href="#4-6-调用函数（函数、方法、构造函数、call、apply）" class="headerlink" title="4.6 调用函数（函数、方法、构造函数、call、apply）"></a>4.6 调用函数（函数、方法、构造函数、call、apply）</h3><hr>
<ul>
<li>使用四种不同场景或模式调用函数<ul>
<li>作为函数</li>
<li>作为方法</li>
<li>作为构造函数</li>
<li>使用<code>call</code>、<code>apply</code></li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// function pattern</span></span><br><span class="line"><span class="keyword">var</span> myFunction = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;<span class="keyword">return</span> <span class="string">'foo'</span>&#125;;</span><br><span class="line"><span class="built_in">console</span>.log(myFunction()); <span class="comment">// log 'foo'</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// method pattern</span></span><br><span class="line"><span class="keyword">var</span> myObject = &#123;<span class="attr">myFunction</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;<span class="keyword">return</span> <span class="string">'bar'</span>;&#125;&#125;</span><br><span class="line"><span class="built_in">console</span>.log(myObject.myFunction()); <span class="comment">// log 'bar'</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// constructor pattern</span></span><br><span class="line"><span class="keyword">var</span> Cody = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="keyword">this</span>.living = <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">this</span>.age = <span class="number">33</span>;</span><br><span class="line">    <span class="keyword">this</span>.gender = <span class="string">'male'</span>;</span><br><span class="line">    <span class="keyword">this</span>.getGender = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="keyword">return</span> <span class="keyword">this</span>.gender;&#125;;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> cody = <span class="keyword">new</span> Cody(); <span class="comment">// invoke via Cody constructor</span></span><br><span class="line"><span class="built_in">console</span>.log(cody); <span class="comment">// logs cody object and properties</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// apply() and call() pattern</span></span><br><span class="line"><span class="keyword">var</span> greet = &#123;</span><br><span class="line">    runGreet: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="keyword">this</span>.name,<span class="built_in">arguments</span>[<span class="number">0</span>],<span class="built_in">arguments</span>[<span class="number">1</span>]);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> cody = &#123;<span class="attr">name</span>:<span class="string">'cody'</span>&#125;;</span><br><span class="line"><span class="keyword">var</span> lisa = &#123;<span class="attr">name</span>:<span class="string">'lisa'</span>&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">//invoke the runGreet function as if it were inside of the cody object</span></span><br><span class="line">greet.runGreet.call(cody,<span class="string">'foo'</span>,<span class="string">'bar'</span>); <span class="comment">//logs cody</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//invoke the runGreet function as if it were inside of the lisa object</span></span><br><span class="line">greet.runGreet.apply(lisa, [<span class="string">'foo'</span>,<span class="string">'bar'</span>]); <span class="comment">//logs lisa</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* Notice the difference between call() and apply() in how parameters are sent to the function being invoked */</span></span><br></pre></td></tr></table></figure>
<h2 id="第六章-this关键字"><a href="#第六章-this关键字" class="headerlink" title="第六章 this关键字"></a>第六章 this关键字</h2><hr>
<h3 id="6-1-this概要及this如何引用"><a href="#6-1-this概要及this如何引用" class="headerlink" title="6.1 this概要及this如何引用"></a>6.1 this概要及this如何引用</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> cody = &#123;</span><br><span class="line">    living : <span class="literal">true</span>,</span><br><span class="line">    age : <span class="number">23</span>,</span><br><span class="line">    gender : <span class="string">'male'</span>,</span><br><span class="line">    getGender : <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="keyword">return</span> cody.gender;&#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(cody.getGender()); <span class="comment">// logs 'male'</span></span><br></pre></td></tr></table></figure>
<ul>
<li>使用<code>this</code>来重写<code>copy</code>对象</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> cody = &#123;</span><br><span class="line">    living: <span class="literal">true</span>, </span><br><span class="line">    age: <span class="number">23</span>, </span><br><span class="line">    gender: <span class="string">'male'</span>, </span><br><span class="line">    getGender: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="keyword">return</span> <span class="keyword">this</span>.gender;&#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(cody.getGender()); <span class="comment">// logs 'male'</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>this</code>，只要记住，总的来说，<code>this</code>是在函数内部使用，用来引用包含函数的对象，而不是函数本身【使用<code>call</code>、<code>apply</code>、<code>new</code>情况例外】</li>
</ul>
<h3 id="6-2-如何确定this值"><a href="#6-2-如何确定this值" class="headerlink" title="6.2 如何确定this值"></a>6.2 如何确定this值</h3><hr>
<ul>
<li><code>this</code>值会被传递给所有函数，其值基于在运行时调用函数的上下文</li>
</ul>
<h3 id="6-3-在嵌套函数中用this关键字引用head对象"><a href="#6-3-在嵌套函数中用this关键字引用head对象" class="headerlink" title="6.3 在嵌套函数中用this关键字引用head对象"></a>6.3 在嵌套函数中用this关键字引用head对象</h3><hr>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> myObject = &#123;</span><br><span class="line">    func1: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="keyword">this</span>); <span class="comment">// logs myObject</span></span><br><span class="line">        <span class="keyword">var</span> func2 = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="keyword">this</span>) <span class="comment">// logs window, and will do so from this point on</span></span><br><span class="line">            <span class="keyword">var</span> func3 = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">                <span class="built_in">console</span>.log(<span class="keyword">this</span>); <span class="comment">// logs window, as it’s the head object</span></span><br><span class="line">            &#125;();</span><br><span class="line">        &#125;();</span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">myObject.func1();</span><br></pre></td></tr></table></figure>
<ul>
<li>总结：当<code>this</code>值的宿主函数被封装在另一个函数的内部或在另一个函数的上下文中被调用时，<code>this</code>值永远是对<code>window</code>对象的引用</li>
</ul>
<h3 id="6-4-充分利用作用域链研究嵌套函数问题"><a href="#6-4-充分利用作用域链研究嵌套函数问题" class="headerlink" title="6.4 充分利用作用域链研究嵌套函数问题"></a>6.4 充分利用作用域链研究嵌套函数问题</h3><hr>
<ul>
<li>可以简单在父函数中使用作用域链来保留对<code>this</code>的引用，以便<code>this</code>值不丢失</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> myObject = &#123;</span><br><span class="line">    myProperty: <span class="string">'I can see the light'</span>, </span><br><span class="line">    myMethod : <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">var</span> that = <span class="keyword">this</span>; <span class="comment">// myMethod 作用域内，保存this引用（也就是myObject）</span></span><br><span class="line">        <span class="keyword">var</span> helperFunction = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123; <span class="comment">// 字函数</span></span><br><span class="line">            </span><br><span class="line">            <span class="built_in">console</span>.log(that.myProperty); <span class="comment">// logs 'I can see the light'</span></span><br><span class="line">            <span class="built_in">console</span>.log(<span class="keyword">this</span>); <span class="comment">// logs window object, if we don't use "that"</span></span><br><span class="line">        &#125;();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">myObject.myMethod(); <span class="comment">// 调用 myMethod</span></span><br></pre></td></tr></table></figure>
<h3 id="6-5-使用call-、apply-控制this值"><a href="#6-5-使用call-、apply-控制this值" class="headerlink" title="6.5 使用call()、apply()控制this值"></a>6.5 使用call()、apply()控制this值</h3><hr>
<ul>
<li><code>this</code>值通常取决于调用函数的上下文，但我们可以使用<code>apply</code>、<code>call</code>重写<code>this</code>值</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> myObject = &#123;&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> myFunction = <span class="function"><span class="keyword">function</span>(<span class="params">param1, param2</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 调用函数的时候，通过call，将this指向myObject</span></span><br><span class="line">    <span class="keyword">this</span>.foo = param1;</span><br><span class="line">    <span class="keyword">this</span>.bar = param2;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>) <span class="comment">// logs Object &#123;foo = 'foo', bar = 'bar'&#125;</span></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">myFunction.call(myObject, <span class="string">'foo'</span>, <span class="string">'bar'</span>); <span class="comment">// invoke function, set this value to myObject</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(myObject) <span class="comment">// logs Object &#123;foo = 'foo', bar = 'bar'&#125;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> myObject = &#123;&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> myFunction = <span class="function"><span class="keyword">function</span>(<span class="params">param1, param2</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 调用函数的时候，通过apply()，将this指向myObject</span></span><br><span class="line">    <span class="keyword">this</span>.foo = param1;</span><br><span class="line">    <span class="keyword">this</span>.bar = param2;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>) <span class="comment">// logs Object &#123;foo = 'foo', bar = 'bar'&#125;</span></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">myFunction.apply(myObject, [<span class="string">'foo'</span>, <span class="string">'bar'</span>]); <span class="comment">// invoke function, set this value</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(myObject) <span class="comment">// logs Object &#123;foo = 'foo', bar = 'bar'&#125;</span></span><br></pre></td></tr></table></figure>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2017/10/24/js-good-style/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2017/10/28/jq-naotu/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
